﻿using System;
using System.Collections;
using System.Collections.Generic;
using Assets.Scripts.NetFrame.Events;
using UnityEngine;
using WorldOfSuperpowers_COMMON;
using WorldOfSuperpowers_COMMON.DataModel;

public class MatchEventHandler : BaseEventHandler {
    

    public override void Response(Dictionary<byte, object> message)
    {
        object Vcontent = new object();
        bool hasGet = message.TryGetValue((byte) EventCode.MatchRoom, out Vcontent);
        if (hasGet)
        {
            EventCode Mcode = (EventCode) Vcontent;
            bool hasGetList = false;
            object model_obj = new object();
            switch (Mcode)
            {
                case EventCode.GetToMatch:
                    hasGetList = message.TryGetValue((byte) Mcode, out model_obj);
                    if (hasGetList)
                    {
                        //找到匹配对象，进入Ban选界面
                        GetToMatchModel model = ProtoTranslater.GetInstance().GetTypeFromBytes<GetToMatchModel>(model_obj);
                        //将玩家信息传入到MatchManager中处理界面显示
                        MatchManager._instance.ShowMatchPanel(model);
                    }
                    break;
                //todo 第二次ban机会没收到，焦点技能框显示异常
                case EventCode.ChooseSkillToBan:
                    hasGetList = message.TryGetValue((byte)Mcode, out model_obj);
                    if (hasGetList)
                    {
                        //有值，则是Ban结果，显示在界面上
                        BPInfos infos = ProtoTranslater.GetInstance().GetTypeFromBytes<BPInfos>(model_obj);
                        MatchManager._instance.ShowBPInfo(infos.SkillisBan,infos.SkillID,true);
                    }
                    else
                    {
                        //没值，则是开始进入BP阶段，正常Ban
                        MatchManager._instance.ChangeMatchStatus(2);
                    }
                    break;
                case EventCode.ChooseSkillToPick:
                    hasGetList = message.TryGetValue((byte)Mcode, out model_obj);
                    if (hasGetList)
                    {
                        //有值，则是Ban结果，显示在界面上
                        BPInfos infos = ProtoTranslater.GetInstance().GetTypeFromBytes<BPInfos>(model_obj);
                        MatchManager._instance.ShowBPInfo(infos.SkillisBan, infos.SkillID, false);
                    }
                    break;
                case EventCode.CountDown:
                    //进入倒计时阶段
                    hasGetList = message.TryGetValue((byte)Mcode, out model_obj);
                    if (hasGetList)
                    {
                        BPInfos infos = ProtoTranslater.GetInstance().GetTypeFromBytes<BPInfos>(model_obj);
                        MatchManager._instance.ShowBPInfo(infos.SkillisBan,infos.SkillID);
                    }
                    break;
                case EventCode.BeginGame:
                    print("收到倒计时结束消息，进入对战场景");
                    MatchManager._instance.ResetMatchManager();
                    break;
            }
        }
    }
}
